/**
 * Copyright (c) 2020-2024, huli.com
 * All rights reserved.
 */
package com.xiaohujr.xuexue.mytest;

/**
 * @author Xue Xue (xuexue1@huli.com)
 * @version 1.0
 * @since 2021/2/4
 */
public class TestQuickSork {
    public static void sort(int[] arr, int low, int high) {
        int i = low, j = high, temp1, temp2;

        if (low > high) {
            return;
        }
        temp1 = arr[low];
        while (i < j) {
            while (arr[j] >= temp1 && i < j) {
                j--;
            }
            while (arr[i] <= temp1 && i < j) {
                i++;
            }
            temp2 = arr[i];
            arr[i] = arr[j];
            arr[j] = temp2;
        }
        arr[low] = arr[i];
        arr[i] = temp1;
        sort(arr, low, i - 1);
        sort(arr, i + 1, high);
    }

    public static void main(String[] args) {
        int[] arr = {10, 7, 2, 4,7};
        sort(arr, 0, arr.length - 1);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }

}
